# -*- coding: utf-8 -*-
# @Author  : haomh
# @Time    : 2025/11/19 15:45
# @Function:


# 1、小猫吃鱼，小猫喝水

# class cat:
#     def set_attr(self,food,sth):
#         self.food = food
#         self.sth = sth
#     def eat(self):
#         print(f'小猫吃{self.food},小猫喝{self.sth}')
#
# cat = cat()
# cat.set_attr('鱼','酒')
#
# cat.eat()

'''
2、小明爱跑步，爱吃东西。
    1）小明体重75.0公斤
    2）每次跑步会减肥0.5公斤
    3）每次吃东西体重会增加1公斤
    4）小美的体重是45.0公斤
'''

# 小明类
# class Human:
#     def __init__(self, name, weight):
#         self.name = name
#         self.weight = weight
#
#     def run(self, weight):
#         self.weight = weight - 0.5
#
#     def eat(self, weight):
#         self.weight = weight + 1
#
#     def __str__(self):
#         return f'{self.name},体重是{self.weight}'
#
#
# xiaoming = Human('xiaoming', 100)
# xiaoming.run(xiaoming.weight)
# xiaoming.eat(xiaoming.weight)
# print(xiaoming)

#

'''
3、摆放家具
    需求：
    1）.房子有户型，总面积和家具名称列表
       新房子没有任何的家具
    2）.家具有名字和占地面积，其中
       床：占4平米
       衣柜：占2平面
       餐桌：占1.5平米
    3）.将以上三件家具添加到房子中
    4）.打印房子时，要求输出:户型，总面积，剩余面积，家具名称列表
'''

# class Furniture():
#     def __init__(self, name, area):
#         self.name = name
#         self.area = area
#
# class House:
#
#     def __init__(self, kind, area):
#         self.kind = kind
#         self.area = area
#         self.free_area = area
#         self.furniture = []
#
#     def add_furniture(self, item):
#         # 容纳家具
#         if self.free_area >= item.area:
#             self.furniture.append(item.name)
#             self.free_area -= item.area
#         else:
#             print('家具太大，剩余⾯积不足，⽆无法容纳')
#     def __str__(self):
#         return f'房⼦户型是{self.kind}, 占地⾯面积{self.area}, 剩余⾯面积{self.free_area}, 家具有{self.furniture}'
#
#
# jiaju1 = Furniture('足球场',10)
#
# house1 = House('两居室',100)
# house1.add_furniture(jiaju1)
# print(house1)
#
#
'''
4.士兵开枪
    需求：
    1）.士兵瑞恩有一把AK47
    2）.士兵可以开火(士兵开火扣动的是扳机)
	士兵也可以装填子弹
    3）.枪 能够 发射子弹(把子弹发射出去)
    4）.枪 能够 装填子弹 --增加子弹的数量
'''


# 枪类
class Gun:
    def __init__(self, model):
        self.model = model
        self.bulletNum = 0

    def addBullet(self, count):
        print('装弹了')
        self.bulletNum += count

    def biubiu(self):
        if self.bulletNum >= 0:
            self.bulletNum -= 1
            print('开枪了')
        else:
            return '没子弹了'


# 士兵类
class Soldier:

    def __init__(self, name):
        self.name = name
        self.gunName = None

    def __str__(self):
        return f'{self.name},{self.gunName}'

    def loadGun(self, count):
        self.gun.add_bullet(count)

    def fire(self):
        self.gunName.biubiu()



ak47 = Gun('Ak47')
man = Soldier('Tom')
man.gunName = ak47
man.fire()
print(man)
